﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Techdays2013.Resources;
using SamuelBlanchard.Extenders;
using Windows.Phone.Speech.VoiceCommands;
using Techdays2013.Codes.SpeechRecognition;

namespace Techdays2013
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += MainPage_Loaded;
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        /// <summary>
        /// On arrive sur la page
        /// </summary>
        /// <param name="e"></param>

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back)
            {
                this.GridFade.Visibility = System.Windows.Visibility.Visible;
                this.GridFade.FadeOut((el) => { el.Visibility = System.Windows.Visibility.Collapsed; });
            }

            base.OnNavigatedFrom(e);
        }

        /// <summary>
        /// Navigation
        /// </summary>
        /// <param name="xmlPage"></param>

        private void Navigate(string xmlPage)
        {
            this.GridFade.Visibility = System.Windows.Visibility.Visible;
            this.GridFade.FadeIn((s) => { NavigationService.Navigate(new Uri("/" + xmlPage, UriKind.Relative)); });
        }

        /// <summary>
        /// Text2Speech
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Tile_Click_TextToSpeech(object sender, RoutedEventArgs e)
        {
            this.Navigate("TextToSpeechPage.xaml");
        }

        /// <summary>
        /// Reconnaissance vocale
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Tile_Click_RecognitionSpeech(object sender, RoutedEventArgs e)
        {
            this.Navigate("SpeechRecognitionPage.xaml");
        }

        private void Tile_Click_AppToApp(object sender, RoutedEventArgs e)
        {
            this.Navigate("AppToAppPage.xaml");
        }

        private void Tile_Click_Controls(object sender, RoutedEventArgs e)
        {
            this.Navigate("ControlsPage.xaml");
        }

        private void Tile_Click_Launchers(object sender, RoutedEventArgs e)
        {
            this.Navigate("LaunchersPage.xaml");
        }

        /// <summary>
        /// Chargement de la page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            VoiceCommandHelper.RegisterVoiceCommands();
        }


    }
}